use std::collections::HashMap;
use bytes::BytesMut;
use rpc::{RpcContext, RpcResult};
use rpc::codec::RpcEncode;

struct Context {
    data: HashMap<String, String>,
}

trait RouterTest {
    fn executor(&self, context: &mut Context)-> RpcResult<()>;
}

trait RouterFactory {
    fn parse(&self, bytes: BytesMut) -> Box<dyn RouterTest>;
}

struct RouterTestDemo;
impl RouterTest for RouterTestDemo {
    fn executor(&self, context: &mut Context) -> RpcResult<()> {
        Ok(())
    }
}

struct RouterFactoryDemo;
impl RouterFactory for RouterFactoryDemo {
    fn parse(&self, bytes: BytesMut) -> Box<dyn RouterTest> {
        Box::new(RouterTestDemo {})
    }
}

#[test]
fn router_test() {
    let mut context = Context{data: HashMap::new()};
    let router_factory = Box::new(RouterFactoryDemo);
    let mut router = router_factory.parse(BytesMut::new());
    let result = router.executor(&mut context);
    let mut t = &mut context;
}

trait GenalTest {

    fn test<T>(&self, data: T);
}

fn dd(data: &mut impl GenalTest) {
    data.test(32);
}


#[test]
fn rpc_encode_test() -> RpcResult<()> {
    let mut context = RpcContext::test_context_with_codec_type("bin-code");
    let tt = 32;
    let cc : Box<dyn RpcEncode> = Box::new(tt);
    // let ccc = *cc;
    // let bb = ccc.encode(&context)?;
    Ok(())
}
